// import AsyncStorage from '@react-native-community/async-storage';
import {Platform, Dimensions} from 'react-native';
import {setI18nLang} from '../../i18n';

export default {
  namespace: 'common',
  state: {
    windowWidth: Dimensions.get('window').width || 375,
    windowHeight: Dimensions.get('window').height,
    isIos: Platform.OS === 'ios',
    isAndroid: Platform.OS === 'android',
    langCode: 'zh',
    country: '香港',
    currencyCode: 'HKD',
  },
  // action 返回一个Promise
  effects: {},
  reducers: {
    setLangCode(data, res) {
      setI18nLang(res.payload);
      data.langCode = res.payload;
      return data; // 必须返回state
    },
  },
  // 初始化数据，订阅一个数据源， 并派发 {history} = undefined
  subscriptions: {
    lg({dispatch, history}) {
      // ss
      dispatch({type: 'setLangCode', payload: 'en'});
    },
  },
};
